package com.dlc.shop.systemtest.api.amount;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dlc.shop.bean.model.Giveaway;
import com.dlc.shop.common.util.Json;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;

import java.util.List;

/**
 * @author lpj
 */
public class GiveawayApi {

    /**
     * 分页获取赠品信息
     */
    public static List<Giveaway> getGiveawayPage() {
        String url = Constant.SHOP_URL + "/shop/giveaway/page";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, Page.class)), Page.class).getRecords()), Giveaway.class);
    }

    /**
     * 通过id查询赠品
     */
    public static Giveaway getGiveawayInfo(Long giveawayId) {
        String url = Constant.SHOP_URL + "/shop/giveaway/info/" + giveawayId;
        return HttpUtil.get(url, Giveaway.class);
    }

    /**
     * 新增赠品
     */
    public static void addGiveaway(Giveaway giveaway) {
        String url = Constant.SHOP_URL + "/shop/giveaway";
        HttpUtil.post(url, giveaway);
    }

    /**
     * 修改赠品
     */
    public static void updateGiveaway(Giveaway giveaway) {
        String url = Constant.SHOP_URL + "/shop/giveaway";
        HttpUtil.put(url, giveaway);
    }


    /**
     * 修改赠品活动状态（失效/删除赠品活动）
     */
    public static void updateGiveawayStatus(Integer status, Long giveawayId) {
        String url = Constant.SHOP_URL + "/shop/giveaway/changeStatus?status=" + status + "&giveawayId=" + giveawayId;
        HttpUtil.put(url);
    }

}
